# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname='imaginary'
pkgver=1.2.4
pkgrel=1
pkgdesc="Fast, simple, scalable HTTP microservice for high-level image processing"
url='https://github.com/h2non/imaginary'
arch=('loong64' 'x86_64')
license=('MIT')
depends=('glibc' 'libvips' 'lcms2' 'openjpeg2' 'poppler-glib' 'openslide' 'libjxl')
makedepends=('go')
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/h2non/imaginary/archive/refs/tags/v${pkgver}.tar.gz"
  "imaginary.service")
sha512sums=('f0848158eb0cb70b111c46c24a9ef324114608fca3f73daf97c296a7e7805890f739e9a65e7bce979204f387e528ccffb139b1deb1417b7187a567bc0cbe4c9f'
            'a561c34735bed4eca5bcd20e99e8294d7eaef85a0293ce742981eb4152b3caf7c26a1b07d6680028f82585437d2c35bfae52d4e6a161591864d0ccff78d65c39')

prepare() {
  cd ${pkgname}-${pkgver}
  go mod vendor
}

build() {
  cd ${pkgname}-${pkgver}
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  go build -v -o ${pkgname} \
    -ldflags "-linkmode=external -X main.Version=${pkgver}" \
    .
}

package() {
  install -Dm644 imaginary.service "${pkgdir}/usr/lib/systemd/system/imaginary.service"
  cd ${pkgname}-${pkgver}
  install -Dm644 "README.md" "$pkgdir/usr/share/doc/${pkgname}/README.md"
  install -Dm644 "LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm755 ${pkgname} -t "${pkgdir}"/usr/bin/
}

# vim: ts=2 sw=2 et:
